<?php


namespace app\reimburse\model;


use app\project\model\Category;
use app\user\model\User;
use think\Model;
use think\model\concern\SoftDelete;

class Project extends Model
{
    use SoftDelete;

    protected $deleteTime = 'delete_time';

    protected $defaultSoftDelete = 0;

    protected $append = [
        'status_name','type_name'
    ];

    public function principalUser()
    {
        return $this->hasOne(User::class,'id','principal')->bind(['principal_name'=>'username']);
    }
    public function teamUser()
    {
        return $this->hasOne(User::class,'id','team')->bind(['team_name'=>'username']);
    }
    public function category()
    {
        return $this->hasOne(Category::class,'id','category_id')->bind(['category_name'=>'title']);
    }
    public function getStatusNameAttr($value,$data){
        if ($data['status']==0){
            $value = '待项目负责人审核';
        }elseif ($data['status']==1){
            $value = '待项目总责人审核';
        }elseif ($data['status']==2){
            $value = '已通过所有审核';
        }else{
            $value = '获取器未设置该值';
        }
        return $value;
    }

    public function getTypeNameAttr($value,$data)
    {
        if ($data['type']==0){
            $value = '教学';
        }elseif ($data['type']==1){
            $value = '科研';
        }elseif ($data['type']==2){
            $value = '人才经费';
        }else{
            $value = '其他';
        }
        return $value;
    }
}